<%@ page import="com.ld.businesscard_manage.service.BusinessCardService" %>
<%@ page import="com.ld.businesscard_manage.service.impl.BusinessCardServiceImpl" %>
<%@ page import="com.ld.businesscard_manage.bean.BusinessCard" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ld.businesscard_manage.bean.User" %>
<%@ page import="com.ld.businesscard_manage.service.RecyleService" %>
<%@ page import="com.ld.businesscard_manage.service.impl.RecyleServiceImpl" %>
<%@ page import="com.ld.businesscard_manage.bean.Recyle" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-18
  Time: 9:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>回收站信息</title>
    <style>
        td {
            color: #ff4b2b;
            margin-left: 20px;
            text-align: center;
        }
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        a {
            text-decoration: none;
            color: black;
        }
        .container {
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35), 0 10px 10px rgba(0, 0, 0, 0.22);
            position: relative;
            overflow: hidden;
            width: 80%;
            max-width: 100%;
            min-height: 480px;
            margin:0 auto;
        }
        </style>
</head>
<body>
<%!
    private RecyleService recyleService = new RecyleServiceImpl();
	private BusinessCardService cardService = new BusinessCardServiceImpl();
%>
<%
    User user = (User)(session.getAttribute("user"));
	String name = request.getParameter("name");
    List<Recyle> recyles = recyleService.getRecylesByLike(user,name);
    if(user.getStatus() == 0){
        out.println("<a href='/home/myRecyle.jsp' style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:blue'>返回个人回收站管理页面</a><br>");
    }else {
        out.println("<a href='/home/manageRecyle.jsp' style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:blue'>返回回收站管理页面</a><br>");
    }
    if (recyles.isEmpty()) out.println("<h1 style='width: 80%;height:400px;margin: 0 auto;text-align:center;line-height:400px'>暂无更多信息!<h1>");
    else {
        out.println("<table class='container'>" +
                "<tr>" +
                "<th>姓名</th>" +
                "<th>用户名</th>" +
                "<th>删除时间</th>" +
                "<th>恢复</th>" +
                "<th>彻底删除</th>" +
                "</tr>");
        if (!recyles.isEmpty())
            for (Recyle recyle : recyles) {
                BusinessCard card = cardService.getCardById(recyle.getBusinesscard_id());
                String recoverDOM = "<td><a class='recover' href=" + "'/home/recoverRecyle.jsp?id=" + card.getId() + "'>恢复" + "</a></td>";
                String deletedDOM = "<td ><a class='deleted' href=" + "'/home/deletedCard.jsp?id=" + card.getId() + "'>彻底删除" + "</a></td>";
                out.println("<tr>");
                out.println("<td style='text-align:center'>" + card.getName() + "</td>");
                out.println("<td style='text-align:center'>" + card.getAccount() + "</td>");
                out.println("<td style='text-align:center'>" + recyle.getTime() + "</td>");
                out.println(recoverDOM);
                out.println(deletedDOM);
                out.println("</tr>");
            }
        out.println("</table>");
    }
%>
</body>
<script>
    let deleted = document.getElementsByClassName("deleted");
    for (let i = 0; i < deleted.length; i++) {
        deleted[i].addEventListener("click",(e) => {
            let b = confirm("你确定要彻底删除吗?");
            if(b == false){
                e.preventDefault();
            }
        })
    }
    let recover = document.getElementsByClassName("recover");
    for (let i = 0; i < recover.length; i++) {
        recover[i].addEventListener("click",(e) => {
            let b = confirm("你确定要恢复吗?");
            if(b == false){
                e.preventDefault();
            }
        })
    }
</script>
</html>
